package com.cakeshop.listener;

import com.cakeshop.model.Comment;
import com.cakeshop.service.CommentService;
import com.cakeshop.service.impl.CommentServiceImpl;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.annotation.*;
import java.util.List;

/**
 * @author nineice
 */
@WebListener
public class RequestListener implements ServletRequestListener{

    public RequestListener() {
    }

    @Override
    public void requestDestroyed(ServletRequestEvent sre) {

    }

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        CommentService commentService = new CommentServiceImpl();
        List<Comment> commentList = commentService.getAllComment();
        sre.getServletRequest().setAttribute("commentList", commentList);
        sre.getServletRequest().setAttribute("Gson", new Gson());
        sre.getServletRequest().setAttribute("commentClass", Comment.class);
    }
}
